"use strict";

var _promise = require("babel-runtime/core-js/promise");

var _promise2 = _interopRequireDefault(_promise);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* eslint-disable no-extend-native */
_promise2.default.prototype.finally = function promiseFinally(callback) {
  var p = this.constructor;
  // We don’t invoke the callback in here,
  // because we want then() to handle its exceptions
  return this.then(
  // Callback fulfills: pass on predecessor settlement
  // Callback rejects: pass on rejection (=omit 2nd arg.)
  function (value) {
    return p.resolve(callback()).then(function () {
      return value;
    });
  }, function (reason) {
    return p.resolve(callback()).then(function () {
      throw reason;
    });
  });
};